import {
  methods,
  request,
  request_address_local,
  testsource,
} from '../utils/request'; //设置自己的request路径

const actions = {
  getAll: {
    name: 'gradeList',
    url: '/learninganalysis/gradeinfo/gradeList/get/',
  },
  getOther: {
    name: 'otherGrade',
    url: '/learninganalysis/gradeinfo/otherGrade/get/',
  },
  getScoreDetail: {
    name: 'courseScoreDetail',
    url: '/learninganalysis/gradeinfo/courseScoreDetail/get/',
  },
};

const customRequest = (
  action: any,
  token: string = '',
  formdata: any = null,
) => {
  let options: any = {
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      Accept: 'application/json',
      Authorization: token ? token : '',
    },
  };
  let url = action.url;
  switch (action.name) {
    case actions.getAll.name:
      options['method'] = methods.get;
      url += formdata;
      break;
    case actions.getOther.name:
      options['method'] = methods.get;
      url += formdata;
      break;
    case actions.getScoreDetail.name:
      options['method'] = methods.get;
      url += formdata;
      break;
    default:
  }

  return request(testsource + url, options);
};

export function getAll(token: string = '', formdata: any = null) {
  return customRequest(actions.getAll, token, formdata);
}

export function getOther(token: string = '', formdata: any = null) {
  return customRequest(actions.getOther, token, formdata);
}
export function getScoreDetail(token: string = '', formdata: any = null) {
  return customRequest(actions.getScoreDetail, token, formdata);
}
